/* vim: set expandtab shiftwidth=4: -*- mode: c++; c-basic-offset: 4; tab-width: 8; indent-tabs-mode: nil -*-
EasyForms
An easy-to-use program for completing scanned documents.
Copyright (C) 2006-2007 Wesley Crossman
Email: wesley@crossmans.net

You can redistribute and/or modify this software under the terms of the GNU
General Public License as published by the Free Software Foundation;
either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this
program; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
Suite 330, Boston, MA 02111-1307 USA */

#ifndef FORMS_DOCUMENT_H
#define FORMS_DOCUMENT_H

#include <QObject>
#include <QList>
#include <QString>
#include <QPixmap>
class FormsDocumentScene;
class FormsDocument;

class FormsPage : public QObject {
Q_OBJECT
public:

    FormsPage(const QString &fileName, const QString &title, QObject *parent = NULL);
    ~FormsPage();
    FormsDocumentScene *getPage();
    void free();
    QString getTitle() {return title;}
    void setTitle(const QString &title);

protected:

    QString fileName, title;
    FormsDocumentScene *view;
    void createView();

signals:

    void titleChanged(QString title);

};


class FormsDocument : public QObject {
Q_OBJECT
public:

    FormsDocument(QObject *parent = NULL);
    FormsDocument(const QString &fileName, QObject *parent = NULL);
    ~FormsDocument();

    bool hasError() {return !error.isNull();}
    QString getError() {return error;}

    void saveAs(const QString &fileName);
    void save();
    bool isOnDisk() {return !fileName.isNull();}
    QString getFileName() {return fileName;}

    void toStart();
    void toEnd();
    void previous();
    void next();
    bool atStart() {return !pages.size() || index == 0;}
    bool atEnd() {return !pages.size() || index == pages.size()-1;}
    int size() {return pages.size();}
    bool isEmpty() {return pages.isEmpty();}
    FormsDocumentScene *getPage();

    void addPage(const QString &fileName, QString title, int index = -1);
    void deletePage(int index = -1);

protected:

    QString fileName, error;
    QList < FormsPage * > pages;
    int index;

signals:

    void selectedPageChanged(int index, QString title);
    void countChanged(int count);
    void saved();

};

#endif

